<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.1</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <#include "common/header-static.ftl">
</head>
<body>
<#include "common/header-nav.ftl">
<div class="x-body">
    <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so">
            <div class="layui-input-inline">
              <input class="layui-input" placeholder="开始日" name="start" id="start">
              <input class="layui-input" placeholder="截止日" name="end" id="end">
            </div>
            <div class="layui-input-inline">
              <@selectTag id = 'payState' dictId = '10' layFilter="payState">${printf}</@selectTag>
            </div>
            <div class="layui-input-inline">
                <@selectTag id = 'payMethod' dictId = '13'>${printf}</@selectTag>
            </div>
            <div class="layui-input-inline">
                <@selectTag id = 'orderState' dictId = '15' laySearch = "true" >${printf}</@selectTag>
            </div>
            <input type="text" name="username"  placeholder="请输入订单号" autocomplete="off" class="layui-input">
            <a class="layui-btn" data-type="reload">搜索</a>
        </form>
    </div>
    <table id="demo" lay-filter="test"></table>
</div>

<script type="text/html" id="toolbarDemo">
  <div class="layui-btn-container">
    <button class="layui-btn layui-btn-sm" lay-event="add">添加</button>
    <button class="layui-btn layui-btn-sm" lay-event="delete">删除</button>
    <button class="layui-btn layui-btn-sm" lay-event="update">编辑</button>
  </div>
</script>
<input type="hidden" id="detailParam" value="{'id':123,'name':'duheng'}">

<input type="hidden" id="getUploadDomain" value="${ftlFunc.getUploadDomain!''}">
<script>
    layui.use(['table','laydate','form'], function(){
        var $ = layui.$;
        var laydate = layui.laydate;
        var table = layui.table;
        var form = layui.form;
        //执行一个laydate实例
        laydate.render({
            elem: '#start' //指定元素
          ,type: 'datetime'
        });
        laydate.render({
            elem: '#end' //指定元素
          ,type: 'datetime'
        });
        //这里渲染表格
        table.render({
           elem: '#demo'
          ,height: 'full-160'
          ,even: true
          ,size: 'sm'
          ,toolbar: '#toolbarDemo'
          ,method: 'post'
          ,url: '${request.contextPath}/search/commonSearch' //数据接口
          ,where: {sqlId: 'order_list'}
          ,parseData: function(res){ //res 即为原始返回的数据
            console.log(res);
            return {
              "code": res.code, //解析接口状态
              "msg": res.message, //解析提示文本
              "count": res.total,//res.total, //解析数据长度
              "data": res.data //解析数据列表
            };
          }
          ,page: true //开启分页
          ,contentType: 'application/json'
          ,limits: [10,30,50]
          ,cols: [[ //表头
             {field: 'userAgentId', title: 'ID', width:60,  fixed: 'left',type:'checkbox'}
            ,{field: 'login_name', title: '登录名', width:100}
            ,{field: 'link_name', title: '联系人', width:100, sort: true}
            ,{field: 'link_phone', title: '联系方式', width:180,
               templet: function (d) {
                 return "手机号为:"+d.link_phone;
               }
             }
            ,{title: '操作', width:180,
              templet: function (d) {
                var aId = d.userAgentId;
                return "<a href='javascript:void(0);' onclick=detailPage('"+aId+"') >编辑</a>";
              }
             }
          ]]
        });
        //这里是查询
        var active = {
          reload: function(){
            table.reload('demo', {
              where: {
                sqlId: 'order_list',
                param: {'loginName':'aab'},
                showSql:true
              }
              ,page: {
                curr: 1 //重新从第 1 页开始
              }
            });
          }
        };
        $('.layui-btn').on('click', function(){
          var type = $(this).data('type');
          active[type] ? active[type].call(this) : '';
        });

      //监听事件
      table.on('toolbar(test)', function(obj){
        var checkStatus = table.checkStatus(obj.config.id);
        console.log(checkStatus.isAll );
        console.log(checkStatus.data);
        switch(obj.event){
          case 'add':
            layer.msg('添加');
            break;
          case 'delete':
            layer.msg('删除');
            break;
          case 'update':
            layer.msg('编辑');
            break;
        }
      });

      form.on('select(payState)', function(data){
        var val = data.value;
        console.log(val);
      });
    });

    function detailPage(val){
      var page = "/admin/order";
      var title = "测试标题";
      layer_show_detail(title,page,true);
    }

    function reloadTable(){
      $('.layui-btn').click();
    }
</script>
</body>

</html>